package com.em.sugarfight.entity;

import java.util.Objects;

public class PathNode implements Comparable<PathNode> {
    private Position position;
    private double cost;          // g值：从起点到当前点的实际代价
    private double heuristic;     // h值：从当前点到终点的启发式估计
    private PathNode parent;      // 父节点，用于重建路径

    public PathNode(Position position, double cost, double heuristic) {
        this.position = position;
        this.cost = cost;
        this.heuristic = heuristic;
    }

    /**
     * f值 = g值 + h值
     */
    public double getFValue() {
        return cost + heuristic;
    }

    @Override
    public int compareTo(PathNode other) {
        return Double.compare(this.getFValue(), other.getFValue());
    }

    // Getters and Setters
    public Position getPosition() { return position; }
    public double getCost() { return cost; }
    public void setCost(double cost) { this.cost = cost; }
    public double getHeuristic() { return heuristic; }
    public PathNode getParent() { return parent; }
    public void setParent(PathNode parent) { this.parent = parent; }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (!(obj instanceof PathNode)) return false;
        PathNode other = (PathNode) obj;
        return Objects.equals(position, other.position);
    }

    @Override
    public int hashCode() {
        return Objects.hash(position);
    }
}
